package com.wuseguang.springcloud.controller;


import com.wuseguang.springcloud.Filter.RequestParameterWrapper;
import com.wuseguang.springcloud.dao.repository.TeacherSubscriptionRepository;
import com.wuseguang.springcloud.service.TeacherSubscriptionService;
import com.wuseguang.springcloud.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 教师订阅表 前端控制器
 * </p>
 *
 * @author 
 * @since 2020-05-26
 */
@RestController
@RequestMapping("/quartz")
public class TeacherSubscriptionController {

    @Autowired
    private TeacherSubscriptionService teacherSubscriptionServiceImpl;


    /**
     * 查询教师课表订阅信息
     * @param request
     * @return
     */
    @RequestMapping("/findTeacherSubscription")
    public Result findTeacherSubscription(RequestParameterWrapper request){
        //学校id
        String schoolId = request.getParam("schoolId");
        //教师id
        String teacherId = request.getParam("teacherId");
        return teacherSubscriptionServiceImpl.findTeacherSubscription(schoolId,teacherId);
    }

    /**
     * 订阅或取消订阅信息
     * @param request
     * @param state 0未订阅/取消订阅，1已订阅
     * @return
     */
    @RequestMapping("/scheduleSubscription")
    public Result scheduleSubscription(RequestParameterWrapper request,
                                       @RequestParam(value = "state") Integer state){
        //学校id
        String schoolId = request.getParam("schoolId");
        //教师id
        String teacherId = request.getParam("teacherId");
        return teacherSubscriptionServiceImpl.scheduleSubscription(state,teacherId,schoolId);
    }

    /**
     * 开启
     * @param request
     */
    @RequestMapping("/openTask")
    public Result openTask(RequestParameterWrapper request){
        //学校id
        String schoolId = request.getParam("schoolId");

        teacherSubscriptionServiceImpl.openTask(schoolId);

        return  new Result();
    }
}

